<template>
关键字：<input type="text" v-model="TiaoJian.Name">
公告类型:<select v-model="TiaoJian.Tid">
    <option :value="-1">--请选择---</option>
<option v-for="item in XiaLa" :value="item.type_Id">{{ item.type_Name }}</option>
</select>
            
<button class="btn btn-success" @click="daochu">导出</button>
<button @click="ShowGong" class="btn btn-success">搜索</button>
<table class="table table-bordered">
 <thead>
    <tr>
        <th>公告id</th>
        <th>公告标题</th>
        <th>发布人</th>
        <th>公告类型</th>
        <th>公告内容</th>
        <th>公告状态</th>
        <th>发布时间</th>
          <th>操作</th>
    </tr>
 </thead>
 <tbody>
    <tr v-for="item in ShowGongGao">
        <th>{{ item.gongGao_Id }}</th>
        <th>{{ item.gongGao_Name }}</th>
        <th>{{ item.gongGao_Fabu }}</th>
        <th>{{ item.type_Name }}</th>
        <th>{{ item.gongGao_NeiRong }}</th>
        <th>{{ item.gongGao_State?"显示":"隐藏" }}</th>
        <th>{{moment(item.gongGao_Time).format('YYYY-MM-DD hh:mm:ss')  }}</th>
          <th><button @click="Add">添加</button></th>
    </tr>
 </tbody>
</table>

</template>

<script setup lang="ts">


import axios from 'axios';
import { ref,onMounted } from 'vue';
import moment from 'moment';
import { useRouter } from 'vue-router';


const TiaoJian=ref({  //查询条件
    Name:"", 
    Tid:-1,


})

onMounted(()=>{
    XiaLa1();
    ShowGong();
})

const ShowGongGao=ref([{   //接受公告数据的响应式数据

    "gongGao_Id": 1,
    "gongGao_Name": "好公告",
    "gongGao_Fabu": "管理员",
    "type_Id": 1,
    "gongGao_NeiRong": "管理员",
    "gongGao_State": true,
    "type_Name": "服务协议",
    "gongGao_Time": "2024-05-05T00:00:00"


}])



const ShowGong=()=>{   //显示公告的方法

    axios.get('https://localhost:7151/api/GongGao/ShowGongGao',{params:{


        Name:TiaoJian.value.Name,
        Tid:TiaoJian.value.Tid,

    }}).then(res=>{

    ShowGongGao.value=res.data;

    })


}

const XiaLa=ref([{    //下拉的响应式函数
 
 "type_Id": 1,
    "type_Name": "服务协议"


}])

const XiaLa1=()=>{   //下拉的方法


    axios.get('https://localhost:7151/api/GongGao/ShowType').then(res=>{

        XiaLa.value=res.data;

    })
}




const path="C:/Users/31718/Desktop/新建 XLSX 工作表.xlsx"  //导出的地址


const daochu =()=>{  //导出方法

    axios.get('https://localhost:7151/api/GongGao/ImportGongGao',{params:{

        Path:path

    }}).then(res=>{

        if(res.data==1)
    {
        alert('导出成功')
    }
    else
    {
        alert('导出失败')
    }
    })


}

const router = useRouter();
const Add=()=>[
router.push('/AddGongGao')
    


]

</script>